{include file="public/meta" /}
<title>数据库管理</title>
</head>
<body>
<!--_header 作为公共模版分离出去-->
{include file="public/header" /}
<!--/_header 作为公共模版分离出去-->
<!--_menu 作为公共模版分离出去-->
{include file="public/leftmenu" /}
<!--/_menu 作为公共模版分离出去-->
<section class="Hui-article-box">
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> <a href="{:url('Index/index')}">首页</a> <span class="c-gray en">&gt;</span> 数据库管理 <span class="c-gray en">&gt;</span> 数据库备份<a id="btn-refresh" class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
    <div class="Hui-article">
        <article class="cl pd-20">
            <div class="cl pd-5 bg-1 bk-gray mt-20">
                <botton type="button" onclick="data_back()" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe641;</i> 立即备份</botton>
            </div>
            <div class="mt-20">
                <table class="table table-border table-bordered table-hover table-bg table-sort">
                    <thead>
                    <tr class="text-c">
                        <th width="40"><input type="checkbox"></th>
                        <th width="100">表名</th>
                        <th width="60">数据量</th>
                        <th width="60">数据大小</th>
                        <th width="100">创建时间</th>
                        <th width="100">备份状态</th>
                        <th width="100">操作</th>
                    </tr>
                    </thead>
                    {volist name="list" id="val"}
                    <tbody>
                    <tr class="text-c">
                        <td><input type="checkbox" value="{$val['name']}"></td>
                        <td>{$val['name']}</td>
                        <td>{$val['rows']}</td>
                        <td>{$val['data_length']}</td>
                        <td>{$val['create_time']}</td>
                        <td>等待备份....</td>
                        <td class="td-manage">
                            <a style="text-decoration:none" onClick="data_optimize('{$val.name}')" href="javascript:;" title="优化表"><i class="Hui-iconfont">&#xe631;</i>优化表</a>
                            <a style="text-decoration:none" onClick="data_repair('{$val.name}')" href="javascript:;" title="修复表"><i class="Hui-iconfont">&#xe6e1;</i>修复表</a>
                    </tr>
                    </tbody>
                    {/volist}
                </table>
            </div>
        </article>
    </div>
</section>
<!--_footer 作为公共模版分离出去-->
{include file="public/footer" /}
<!--/_footer /作为公共模版分离出去-->
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__LIB__/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="__LIB__/laypage/1.2/laypage.js"></script>
<script type="text/javascript">
    $(function(){
        $('.table-sort').dataTable({
            "aaSorting": [[ 1, "desc" ]],//默认第几个排序
            "bStateSave": true,//状态保存
            "aoColumnDefs": [
                //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
                {"orderable":false,"aTargets":[0,6]}// 制定列不参与排序
            ]
        });
        $('.table-sort tbody').on( 'click', 'tr', function () {
            if ( $(this).hasClass('selected') ) {
                $(this).removeClass('selected');
            }
            else {
                $('tr.selected').removeClass('selected');
                $(this).addClass('selected');
            }
        });
    });
    /*立即备份*/
    function data_back()
    {
        var _tables = new Array();
        $("input[type='checkbox']:checked").each(function(i) {
            _tables[i]=$(this).val();
        });
        if(_tables.length ==0){
            layer.msg("请选择需要操作的记录",{icon:5,time:1000});
            return false;
        }
        ajax_ids(_tables);
    }
    function ajax_ids(_tables) {
        $.ajax({
            url:"{:url('Data/export')}",
            type:'POST',
            data:{ "tables" : _tables },
            dataType:'JSON',
            success:function(data){
                if(data.code==0)
                {
                    layer.msg(data.msg,{icon:6,time:1000},function(){
                        backup(data.data.tab);
                    });
                } else {
                    layer.msg(data.msg,{icon:5,time:1000});
                }
            },
            error:function(data){
                layer.msg(data.msg,{icon:5,time:1000});
            }
        });
    }
    /*备份数据库*/
    function backup(tab,status)
    {
        $.ajax({
            type : "post",
            url : "{:url('Data/export')}",
            data : { "id" : tab.id, "start" : tab.start },
            dataType : "json",
            success : function(data) {
                if (data.code == 0) {
                    backup(data.data.tab, tab.id != data.data.tab.id);
                    layer.msg("正在备份...");
                } else if (data.code==2) {
                    layer.msg("备份完成",{icon:6},function () {
                        window.location.reload();
                    });
                } else {
                    layer.msg(data.msg,{icon:6})
                }
            }
        })
    }

    /*优化表*/
    function data_optimize(id){
        $.ajax({
            url:"{:url('Data/optimize')}",
            type:'post',
            data:{
                'ids':id
            },
            dataType:'json',
            success:function(data){
                if(data.code==0)
                {
                    layer.msg(data.msg,{icon:6,time:1000},function(){
                        window.location.reload();
                    });
                }
                else{
                    layer.msg(data.msg,{icon:5,time:1000});
                }
            },
            error:function(data){
                layer.msg(data.msg,{icon:5,time:1000});
            }
        });
    }
    /*修复表*/
    function data_repair(id){
        $.ajax({
            url:"{:url('Data/repair')}",
            type:'post',
            data:{
                'ids':id
            },
            dataType:'json',
            success:function(data){
                if(data.code==0)
                {
                    layer.msg(data.msg,{icon:6,time:1000},function(){
                        window.location.reload();
                    });
                }
                else{
                    layer.msg(data.msg,{icon:5,time:1000});
                }
            },
            error:function(data){
                layer.msg(data.msg,{icon:5,time:1000});
            }
        });
    }
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>